package com.device_manager.controller;

import com.device_manager.dto.DeviceModelDTO;
import com.device_manager.dto.PageDeviceModelDTO;
import com.device_manager.result.PageResult;
import com.device_manager.result.Result;
import com.device_manager.service.DeviceModelService;
import com.device_manager.vo.PageDeviceModelVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
@Slf4j
@Tag(name="设备型号管理")
public class DeviceModelController {
    @Autowired
    private DeviceModelService deviceModelService;
    @Operation(summary = "新增设备型号")
    @ApiOperationSupport(author = "韩方志")
    @PostMapping("/deviceModel")
    public Result<DeviceModelDTO> CreateDeviceModel(DeviceModelDTO deviceModelDTO){
        deviceModelService.CreateDeviceModel(deviceModelDTO);
        log.info("创建的设备型号是:{}",deviceModelDTO.getDeviceModel());
        return Result.success();
    }
    @Operation(summary = "删除设备型号")
    @PostMapping("/deleteDeviceModel")
    public Result<DeviceModelDTO> deleteDeviceModel(DeviceModelDTO deviceModelDTO){
        deviceModelService.deleteDeviceModel(deviceModelDTO);//根据前端传的金蝶编码删除
        log.info("删除的设备型号ID是:{}",deviceModelDTO.getModelId());
        return Result.success();
    }
    @Operation(summary = "修改设备型号")
    @PostMapping("/updateDeviceModel")
    public Result<DeviceModelDTO> updateDeviceModel(DeviceModelDTO deviceModelDTO){
        deviceModelService.updateDeviceModel(deviceModelDTO);
        log.info("修改的设备型号ID是:{}",deviceModelDTO.getDeviceModel());
        return Result.success();
    }
    @Operation(summary = "查询设备型号列表")
    @PostMapping("/deviceModelList")
    public Result<PageResult<PageDeviceModelVO>> deviceModelList(PageDeviceModelDTO pageDeviceModelDTO){
        PageResult<PageDeviceModelVO>  pageResult = deviceModelService.deviceModelList(pageDeviceModelDTO);
        log.info("查询成功");
        return Result.success(pageResult);
    }
    @Operation(summary = "查询设备型号详情")
    @PostMapping("/{modelId}")
    public Result<PageDeviceModelVO> deviceModelDetail(@PathVariable Long modelId){
        PageDeviceModelVO  pageResult = deviceModelService.deviceModelDetail(modelId);
        log.info("查询的设备型号ID是:{}",modelId);
        return Result.success(pageResult);
    }
}
